import {
  Controller,
  Get,
  Post,
  Body,
  UseGuards,
  SetMetadata,
} from '@nestjs/common';
import { GuardService } from './guard.service';
import { CreateGuardDto } from './dto/create-guard.dto';
import { UpdateGuardDto } from './dto/update-guard.dto';

// 引入守卫
import { RoleGuard } from './role/role.guard';

// 引入 自定义修饰器
//     自定义参数修饰器
import {
  CustomDecorator,
  paramDecoratorTest,
} from './custom-decorator/custom-decorator.decorator';

@Controller('guard')
@UseGuards(RoleGuard)
export class GuardController {
  constructor(private readonly guardService: GuardService) {}

  @Post()
  create(@Body() body: CreateGuardDto) {
    return body;
  }

  // 智能守卫配合局部守卫完成权限管理
  @Get('test1')
  @SetMetadata('role', ['admin'])
  test1(@Body() body: CreateGuardDto) {
    return body;
  }

  @Get('test2')
  @CustomDecorator(['admin'])
  // 自定义参数修饰器获取 url
  test2(@paramDecoratorTest() url) {
    return url;
  }
}
